"""帆软表格的一些辅助方法"""

import werkzeug

from odoo import models, api, fields
from odoo.tools import float_compare
from odoo.exceptions import UserError, ValidationError
from odoo.http import Controller, route, local_redirect, request


class FormUtils(Controller):

    @route(['/fr/direct'], methods=['GET'], auth='public', csrf=False, type='http')
    def fr_jump_to_odoo(self, *args, **kws):
        """跳转向ODOO对象"""
        env = request.env
        query = dict(request.httprequest.values)
        model = query.get('model')
        query['view_type'] = 'form'
        if model == 'sale.order':
            query['action'] = env.ref('sale.action_quotations_with_onboarding').id
            query['menu_id'] = env.ref('sale.menu_sale_quotations').id
        elif model == 'purchase.order':
            query['action'] = env.ref('purchase.purchase_rfq').id
            query['menu_id'] = env.ref('purchase.menu_purchase_rfq').id
        path = '/web#' + werkzeug.url_encode(query)
        return werkzeug.utils.redirect(path, 303)
